package com.witfortos.kotlindemo.common.http

import com.pcl.mvvm.utils.RetrofitClient
import okhttp3.MediaType
import okhttp3.RequestBody

class Req {

    private fun getRequestBody(reqMsg: String): RequestBody = RequestBody.create(MediaType.parse("application/json"), reqMsg);
    private val mService by lazy { RetrofitClient.getInstance().create(Api::class.java) }

    suspend fun login(reqMsg: String) = mService.login(getRequestBody(reqMsg));
    suspend fun getUserInfo() = mService.getUserInfo();
    suspend fun getNews(reqMsg: String) = mService.getNews(getRequestBody(reqMsg))


    companion object {
        @Volatile
        private var req: Req? = null

        fun getInstance() = req ?: synchronized(this) {
            req ?: Req().also { req = it }
        }
    }

}